//
//  SEFollowedDoctorsCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/17.
//

import UIKit

protocol SEFollowedDoctorsCellDelegate: NSObjectProtocol {
    func followedDoctorsCellBtnAction(indexPath: IndexPath)
}

class SEFollowedDoctorsCell: UITableViewCell {

    private var indexPath = IndexPath(row: 0, section: 0)
    weak var delegate: SEFollowedDoctorsCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = .white
        contentView.backgroundColor = .white
    }

    func update(with viewModel: SEFollowedCellViewModel, indexPath: IndexPath) {
        self.indexPath = indexPath
        avatarImageView.kf.setAvatarImage(urlString: viewModel.model.imgUrl,
                                          placeholder: viewModel.avatarPlaceholder)
        nameLabel.text = viewModel.model.name
        departmentLabel.text = viewModel.model.title
        hospitalLabel.text = viewModel.model.caption
        goodAtLabel.text = viewModel.goodAt
    }
    
    @IBAction private func unfollowAction() {
        delegate?.followedDoctorsCellBtnAction(indexPath: indexPath)
    }
    
    @IBOutlet private weak var avatarImageView: UIImageView!
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var departmentLabel: UILabel!
    @IBOutlet private weak var hospitalLabel: UILabel!
    @IBOutlet private weak var goodAtLabel: UILabel!
    
    @IBOutlet private weak var unfollowButton: UIButton! {
        didSet {
            unfollowButton.layer.cornerRadius = unfollowButton.height / 2
        }
    }
    
}
